﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using ControleRepresentante.Logic;
using ControleRepresentante.Logic.Models;
using WebSite.ViewModels.Fields;
using WebSite.ViewModels.IndexViewModels;

namespace WebSite.ViewModels.ViewModelExtensions.IndexViewModelExtensions
{
    public static class PedidoJolitexIndexColumns
    {
        public static Guid CodigoJolitex = new Guid("6a16f011-2f70-4919-94f0-d58320c1e0d8");
        public static Guid Sincronizado = new Guid("64d90caa-967a-43df-897c-dad634daae47");
    }

    public class PedidoJolitexIndexViewModel : IIndexViewModelExtension
    {
        private readonly string m_CodigoJolitex;
        private readonly bool? m_SincronizadoBuscaValue;
        private readonly bool m_AllJolitex;
        private readonly bool m_HasFabricaPermission;

        public PedidoJolitexIndexViewModel(string codigoJolitex, bool? sincronizadoBuscaValue, bool allJolitex, bool hasFabricaPermission)
        {
            m_CodigoJolitex = codigoJolitex;
            m_SincronizadoBuscaValue = sincronizadoBuscaValue;
            m_AllJolitex = allJolitex;
            m_HasFabricaPermission = hasFabricaPermission;
        }

        public IEnumerable<IField> GetSearchFields()
        {
            if (m_HasFabricaPermission)
            {
                yield return new TextBoxField("Pedido Jolitex", "codigoJolitex", m_CodigoJolitex);
                yield return new DropDownListField("Sincronizado", "sincronizado")
                    .AddEmpty(!m_SincronizadoBuscaValue.HasValue)
                    .Add("Sim", true, m_SincronizadoBuscaValue == true)
                    .Add("Não", false, m_SincronizadoBuscaValue == false);
                yield return new CheckBoxField("Todas as fabricas Jolitex", "allJolitex", m_AllJolitex);
            }
        }

        public bool CanEditSpecific(ModelBase modelBase)
        {
            return true;
        }

        public bool CanDeleteSpecific(ModelBase modelBase)
        {
            return true;
        }

        public void RegisterColumns(IndexColumnDefinitionsCollection indexColumnDefinitionsCollection, IIndexColumnsProvider indexColumnsProvider)
        {
            if (m_HasFabricaPermission)
            {
                indexColumnDefinitionsCollection.Register(indexColumnsProvider[PedidoJolitexIndexColumns.CodigoJolitex], x => ((Pedido)x).PedidoJolitex.Codigo);
                indexColumnDefinitionsCollection.Register(indexColumnsProvider[PedidoJolitexIndexColumns.Sincronizado], (x, y) => ((Pedido)x).PedidoJolitex.Sincronizado);
            }
        }

        public IEnumerable<TabItem> GetTabs(HtmlHelper htmlHelper)
        {
            return new TabItem[0];
        }
    }
}